#!/bin/env perl

use strict;
use warnings;
use http_query;
use http_util;
use Data::Dumper;

my $email = 'alabos@163.com';
my $password = 'alabos';

my ($head, $content, $status) = http_query("http://wap.kaixin001.com/");
my $form_content = get_form_content($content, q(action="http://wap.kaixin001.com/home/"));
my $action_url = get_form_action_url($form_content);
my $fields = get_form_input_fields($form_content, qr(hidden|text|password|checkbox|submit));
$fields->{email} = $email;
$fields->{password} = $password;
($head, $content, $status) = http_query($action_url, "POST", hash_to_paired_string($fields, \&url_encode));
if ($status == 302)
{
	my $location_url = get_location_url($head);
	$location_url = sub
	{
		my ($host, $path) = @_;

		return $host . $path;
	}->("http://wap.kaixin001.com", $location_url);

	my ($head, $content, $status) = http_query($location_url);
	if (open(my $fp, ">", "debug.htm"))
	{
		print $fp $content;
		close $fp;
	}
}
